package database;

import java.sql.Connection;
import java.sql.SQLException;

import com.mysql.jdbc.PreparedStatement;

public class Test {
	
	public static void main(String[] args) throws SQLException {
		MyDBPool myDBPool = new MyDBPool();
		
		for(int i = 0; i < 11; i++) {
			new Thread(new Runnable() {
				
				public void run() {
					
					synchronized (myDBPool.getClass()) {
						try {
							Connection conn = myDBPool.getConnection();
							String sql = "insert into person(name,age) values(?,?)";
							PreparedStatement pstmt;
							pstmt = (PreparedStatement) conn.prepareStatement(sql);
							pstmt.setString(1, "wanglong");
							pstmt.setInt(2, 23);
							pstmt.execute();
							pstmt.close();
							conn.close();
							System.out.println("------------");
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
					
				}
			}).start();
		}
		
	}

}
